<template>
  <div>
    <table>
      <tr>
        <td>投资名称</td>
        <td>
          <input type="text" v-model="addData.name" />
        </td>
      </tr>
      <tr>
        <td>投资总额度</td>
        <td>
          <input type="text" v-model="addData.total" />
        </td>
      </tr>
      <tr>
        <td colspan="2"><input type="button" value="添加" @click="add" /></td>
      </tr>
    </table>
  </div>
</template>

<script setup lang="ts">


import { reactive, toRefs } from 'vue';
import { useRouter } from 'vue-router';
import axios from 'axios';

const router = useRouter();

let data = reactive({
  addData: {
    name: '',
    total: ''
  }
});

let { addData } = toRefs(data);

const add = () => {
  axios({
    url: 'http://localhost:56975/api/Invest/PostAddInvest',
    method: 'post',
    data: {
      I_Name: addData.value.name,
      I_Total: addData.value.total
    }
  })
    .then((res) => {
      console.log(res);
      if (res.data > 0) {
        alert('添加成功');
        router.push('/show');
      }
    })
    .catch((err) => {
      console.log(err);
    });
};
</script>

<style scoped></style>
